#include "Locks.h"

using namespace Lk::Threading;

Mutex::Mutex()
{
	InitializeCriticalSection( &m_cs );
}

Mutex::~Mutex()
{
	//Release CS when object goes out of scope
	DeleteCriticalSection( &m_cs );
}

void Mutex::Lock()
{
	EnterCriticalSection( &m_cs );
}

void Mutex::Unlock()
{
	LeaveCriticalSection( &m_cs );
}

Event::Event(const char *eventName) : m_eventName(eventName)
{
	m_eventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
}

Event::~Event()
{
	CloseHandle( m_eventHandle );
}

bool Event::Trigger() volatile
{
	//assert( m_eventHandle == 0);
	return SetEvent( m_eventHandle );
}

void Event::Wait() volatile
{
	//Wait infinitely for event to trigger
	WaitForSingleObject( m_eventHandle, 0xffffffff );
}



